<!-- HTML header for doxygen 1.8.3.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>Sifteo SDK: Sifteo::MotionBuffer&lt; tSize &gt; Struct Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="doxygen-style-overrides.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<center>
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Sifteo SDK" src="sdk_logo.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">
   &#160;<span id="projectnumber">v1.0.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
</center>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Home</span></a></li>
      <li><a href="pages.html"><span>Guides</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li class="current"><a href="annotated.html"><span>Reference</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>Sifteo</b></li><li class="navelem"><a class="el" href="struct_sifteo_1_1_motion_buffer.html">MotionBuffer</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pub-static-attribs">Static Public Attributes</a> &#124;
<a href="struct_sifteo_1_1_motion_buffer-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">Sifteo::MotionBuffer&lt; tSize &gt; Struct Template Reference<div class="ingroups"><a class="el" href="group__motion.html">Motion</a></div></div>  </div>
</div><!--header-->
<div class="contents">

<p>A memory buffer which holds captured motion data.  
 <a href="struct_sifteo_1_1_motion_buffer.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="motion_8h_source.html">sifteo/motion.h</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:ab750cdfb46707c12e07351ebe1a9ba6a"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="struct_sifteo_1_1_motion_buffer.html#ab750cdfb46707c12e07351ebe1a9ba6a">attach</a> (_SYSCubeID id, unsigned hz=100)</td></tr>
<tr class="memdesc:ab750cdfb46707c12e07351ebe1a9ba6a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize the <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a> and attach it to a cube.  <a href="#ab750cdfb46707c12e07351ebe1a9ba6a">More...</a><br/></td></tr>
<tr class="separator:ab750cdfb46707c12e07351ebe1a9ba6a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a29a51e19e1e7864ed46bbe26cc1e5a60"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__math.html#gadf60fc5d5c0643721fc47d903088be0e">Int3</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="struct_sifteo_1_1_motion_buffer.html#a29a51e19e1e7864ed46bbe26cc1e5a60">integrate</a> (unsigned duration)</td></tr>
<tr class="memdesc:a29a51e19e1e7864ed46bbe26cc1e5a60"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculate a numerical integral over recent motion data.  <a href="#a29a51e19e1e7864ed46bbe26cc1e5a60">More...</a><br/></td></tr>
<tr class="separator:a29a51e19e1e7864ed46bbe26cc1e5a60"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-static-attribs"></a>
Static Public Attributes</h2></td></tr>
<tr class="memitem:a3c6c96116960f2d30e71db772c528ded"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a3c6c96116960f2d30e71db772c528ded"></a>
static const unsigned&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="struct_sifteo_1_1_motion_buffer.html#a3c6c96116960f2d30e71db772c528ded">TICK_HZ</a> = _SYS_MOTION_TIMESTAMP_HZ</td></tr>
<tr class="memdesc:a3c6c96116960f2d30e71db772c528ded"><td class="mdescLeft">&#160;</td><td class="mdescRight">Reciprocal of the <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a>'s timestamp unit, in Hertz. <br/></td></tr>
<tr class="separator:a3c6c96116960f2d30e71db772c528ded"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a03dcaddd84e862d6eb134ec6940deadd"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a03dcaddd84e862d6eb134ec6940deadd"></a>
static const unsigned&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="struct_sifteo_1_1_motion_buffer.html#a03dcaddd84e862d6eb134ec6940deadd">TICK_NS</a> = _SYS_MOTION_TIMESTAMP_NS</td></tr>
<tr class="memdesc:a03dcaddd84e862d6eb134ec6940deadd"><td class="mdescLeft">&#160;</td><td class="mdescRight">Duration of the <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a>'s timestamp unit, in nanoseconds. <br/></td></tr>
<tr class="separator:a03dcaddd84e862d6eb134ec6940deadd"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a8b5fb69f39bb685c573c19316b39f9ab"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8b5fb69f39bb685c573c19316b39f9ab"></a>
static const unsigned&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="struct_sifteo_1_1_motion_buffer.html#a8b5fb69f39bb685c573c19316b39f9ab">TICK_US</a> = _SYS_MOTION_TIMESTAMP_NS / 1000</td></tr>
<tr class="memdesc:a8b5fb69f39bb685c573c19316b39f9ab"><td class="mdescLeft">&#160;</td><td class="mdescRight">Duration of the <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a>'s timestamp unit, in microseconds. <br/></td></tr>
<tr class="separator:a8b5fb69f39bb685c573c19316b39f9ab"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template&lt;unsigned tSize = 32&gt;<br/>
struct Sifteo::MotionBuffer&lt; tSize &gt;</h3>

<p>A memory buffer which holds captured motion data. </p>
<p>This is a FIFO buffer which captures timestamped accelerometer samples. Samples are enqueued and timestamps are generated the moment a relevant packet arrives over the radio from a cube. Timestamps are collected using the system clock, and stored as 8-bit deltas.</p>
<p>Like a <a class="el" href="struct_sifteo_1_1_video_buffer.html" title="A memory buffer which holds graphics data.">VideoBuffer</a>, a <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a> can be used with at most one <a class="el" href="struct_sifteo_1_1_cube_i_d.html" title="A lightweight identifier for one Sifteo cube.">CubeID</a> at a time, but this association can change at runtime. The size of a <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a> may also be modified, in order to trade off between capture duration and memory usage.</p>
<p>This captured accelerometer data may be directly read by signal processing code in userspace, or it may be processed with lower CPU overhead with the help of the provided higher-level methods.</p>
<p>MotionBuffers are templatized by buffer size. The default should be sufficient for most uses, but if you need to save a longer motion history the size can be adjusted to a maximum of 256 samples.</p>
<dl class="section warning"><dt>Warning</dt><dd>We don't recommend allocating MotionBuffers on the stack. Usually this wouldn't be a useful thing to do anyway, since MotionBuffers tend to be long-lived objects. But the specific reason we don't recommend this is that the system requires a <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a> pointer to be at least 1kB away from the top of RAM. In other words, it needs to have enough physical memory for the entire size of a maximally-large (256-sample) buffer, even if you've defined the buffer with a smaller size. </dd></dl>
</div><h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="ab750cdfb46707c12e07351ebe1a9ba6a"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;unsigned tSize = 32&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="struct_sifteo_1_1_motion_buffer.html">Sifteo::MotionBuffer</a>&lt; tSize &gt;::attach </td>
          <td>(</td>
          <td class="paramtype">_SYSCubeID&#160;</td>
          <td class="paramname"><em>id</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">unsigned&#160;</td>
          <td class="paramname"><em>hz</em> = <code>100</code>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Initialize the <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a> and attach it to a cube. </p>
<p>When this cube is connected, this <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a> will begin asynchronously receiving a sample every time we receive accelerometer data from the cube over the air.</p>
<p>We will store data as fast as it arrives, but due to power management the system will often try to reduce the rate at which we poll each cube's sensors. When a <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a> is attached to a cube, we can request a particular rate of service, specified here in hertz. This is not a guranteed rate, just a suggestion for power management purposes.</p>
<p>The caller is responsible for ensuring that a <a class="el" href="struct_sifteo_1_1_motion_buffer.html" title="A memory buffer which holds captured motion data.">MotionBuffer</a> is only attached to one cube at a time.</p>
<p>Note that, regardless of the actual size of this motion buffer, the system requires a block of memoryw </p>

</div>
</div>
<a class="anchor" id="a29a51e19e1e7864ed46bbe26cc1e5a60"></a>
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;unsigned tSize = 32&gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__math.html#gadf60fc5d5c0643721fc47d903088be0e">Int3</a> <a class="el" href="struct_sifteo_1_1_motion_buffer.html">Sifteo::MotionBuffer</a>&lt; tSize &gt;::integrate </td>
          <td>(</td>
          <td class="paramtype">unsigned&#160;</td>
          <td class="paramname"><em>duration</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Calculate a numerical integral over recent motion data. </p>
<p>The duration is specified in units as defined by TICK_NS, TICK_US, and TICK_HZ. Numerical integration is performed by the Trapezoid rule, using a non-uniform sampling grid. If the integral duration extends beyond the oldest buffered, sample, we act as if that sample lasted forever. If the integral ends in-between samples, we linearly interpolate.</p>
<p>The result will be scaled by (2 * duration), meaning you'll need to divide by this number to take an average. However, avoiding this division is both faster and preserves precision, so we recommend using the scaled values as-is if possible.</p>
<p>This integration can be used as a very simple "boxcar" or moving-average low pass filter, with a fixed temporal window size. This kind of filter will feel like it's "slowing" or "blurring" motions, but for short durations the filtered results can feel very natural. </p>

</div>
</div>
<hr/>The documentation for this struct was generated from the following file:<ul>
<li><a class="el" href="motion_8h_source.html">motion.h</a></li>
</ul>
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.3.1-->
<!-- start footer part -->
    <hr class="footer"/>
    <address class="footer">
        <p><a href="http://sifteo.com">Sifteo</a> SDK v1.0.0 <small>(see <a href="https://developers.sifteo.com/sifteosdk">all versions</a>)</small></p>
        <p>Last updated Wed Mar 27 2013, by <a href="http://www.stack.nl/~dimitri/doxygen">Doxygen</a></p>
    </address>
</body>
</html>
